﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace AutoUpgradeManager
{
    public partial class BaseWindow:ResourceDictionary
    {

        private void Title_MouseMove(object sender, MouseEventArgs e)
        {
            var window = (Window)((FrameworkElement)sender).TemplatedParent;

            if (window!=null &&  e.LeftButton == MouseButtonState.Pressed)
            {
                window.DragMove();
            }
        }

        private void Title_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var window = (Window)((FrameworkElement)sender).TemplatedParent;

            if (e.ClickCount == 2)
            {
                if (window == null) return;

                window.WindowState = window.WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal;

            }
        }


        private void btn_Click(object sender, RoutedEventArgs e)
        {
            var window = (Window)((FrameworkElement)sender).TemplatedParent;

            Button b = sender as Button;

            if (b == null) return;

            switch (b.Name)
            {
                case "Btn_Min":
                    window.WindowState = WindowState.Minimized;
                    break;
                case "Btn_Max":
                    window.WindowState = window.WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal;
                    break;
                case "Btn_Close":
                    window.Close();
                    break;
                default:
                    break;
            }
            e.Handled = true;

        }
    }
}
